home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1525 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to initialize an array of structures?
  5. Date: Thu, 11 Jan 1996 13:55:10 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d358f$kj9@tahko.lpr.carel.fi>
  8. References: <4d240e$nk5@jupiter.planet.net>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Chris Kemp <chrisk@paladn.com> wrote:
  13.  
  14. >Could someone explain how to do this properly:
  15.  
  16. >        struct FUNCTIONMAP
  17. >        {
  18. >            char     *functionname;
  19. >            int    functionnumber;
  20. >            int    maxargs;
  21. >            int    functarg[5];
  22. >            
  23. >        };
  24. >        
  25. >        static struct FUNCTIONMAP functionlist[300];    
  26. >        functionlist[1]={"firstfunction",1,3,2,2,2,0,0}    <-- hangs on this line
  27. >        
  28. >TIA            
  29.  
  30. You would want to use braces:
  31.  
  32.     static struct FUNCTIONMAP    functionlist[300];
  33.  
  34.     functionlist[0] = { "firstfunction", 1, 3, { 2, 2, 2, 0, 0 } };
  35.  
  36. Or, if you want to initialize more rows at once, why not use:
  37.  
  38.     static struct FUNCTIONMAP    functionlist[300] =
  39.     {
  40.         { "firstfunction", 1, 3, { 2, 2, 2, 0, 0 } },
  41.         { "secondfunc", 1, 3, { 2, 2, 2, 0, 0 } },
  42.         ...    /* etc */
  43.     };
  44.  
  45. BTW, in C/C++, array indexes start at 0 instead of 1.
  46.  
  47. Later,
  48. AriL
  49.  
  50. All my opinions are mine and mine alone.
  51.  
  52.